package model;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

/**
 * 
 * 通过xml的两种注入方法进行注入
 * 1. 属性注入
 * 2. 构造器注入
 * 对于属性注入，是通过 set注入 还是 直接属性= 注入，可以将属性名更改即可
 * @author lcx
 *
 */
@Component("user1")
@Scope("prototype")
//@Lazy(true) Lazy是Spring3.0才增加的
public class SimpleUser {

	private String userName="liu1";
	private int age=20;

	@PostConstruct
	public static void beforeMethod()
	{
		System.out.println("after SimpleUser initialized...");
	}

	/**
	 * 默认构造器
	 * 进行属性注入时候必须要有构造器，否则会报错
	 * @param userName
	 * @param age
	 */
	public SimpleUser()
	{

	}


	/**
	 * 通过构造器注入
	 * @param userName
	 * @param age
	 */
	public SimpleUser(String userName,int age)
	{
		this.userName=userName;
		this.age=age;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	@PreDestroy 
	public static void afterDestroy()
	{
		System.out.println(" SimpleUser will destroy...");
	}

	public void info()
	{
		System.out.println("name="+userName+"   age="+age);
	}
}
